//
//  HMRetweetView.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/10.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
import SnapKit

class HMRetweetView: UIView {


    var bottomConstraint : Constraint?
    
    
    var retweetModel : HMstatusModel? {
        didSet{
        
            retweettext.text = retweetModel?.retweetText
            
            self.bottomConstraint?.uninstall()
            
            if let pic_urls = retweetModel?.hmstatus?.retweeted_status?.pic_urls where pic_urls.count > 0
            {
            
                pictureView.pic_urls = retweetModel?.hmstatus?.retweeted_status?.pic_urls
                pictureView.hidden = false
                
                snp_updateConstraints(closure: { (make) -> Void in
                  self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(magic).constraint
                })
            }
            else
            {
                 pictureView.hidden = true
                
                snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(retweettext.snp_bottom).offset(magic).constraint
                })
            }
            
        }
    }
    
    var pictureModel : HMstatusModel?
    lazy  var retweettext : UILabel = {
    
    let label = UILabel(color: UIColor.darkGrayColor(), font: 15)
        
        label.preferredMaxLayoutWidth =  SCREENW - magic * 2
        
        label.numberOfLines = 0
        return label
    }()
    lazy var pictureView : HMPictureView = {
        let picture = HMPictureView()
        return picture
    }()
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        stetupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func stetupUI() {
    
        backgroundColor = UIColor(white: 0.8, alpha: 1)
        addSubview(retweettext)
        addSubview(pictureView)
       
        retweettext.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(magic)
            make.leading.equalTo(self).offset(magic)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(retweettext.snp_bottom).offset(10)
            make.leading.equalTo(retweettext)
        }
        snp_makeConstraints { (make) -> Void in
            self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(magic).constraint
        }
    }
    
}
